package com.base.vistter.iframe.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.base.vistter.iframe.entity.SysJob;
import com.base.vistter.iframe.exception.IframeException;
import com.base.vistter.iframe.mapper.SysJobMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
@Slf4j
public class SysJobService extends BaseService<SysJobMapper, SysJob> {

    @Transactional(propagation = Propagation.REQUIRED)
    public boolean save(SysJob entity) throws IframeException {
        LambdaQueryWrapper<SysJob> query = new LambdaQueryWrapper<SysJob>();
        query.eq(SysJob::getCode , entity.getCode());
        SysJob sysJob = super.selectOne(query);
        if(sysJob != null){
            throw new IframeException("职务编码已存在");
        }
        return super.save(entity);
    }
}
